#!/usr/bin/python
#coding=utf-8

import MySQLdb

try:
	conn = MySQLdb.connect(host='localhost',port=3306,user='root',passwd='wzyzsl',db='python',charset='utf8') #端口号是port 连接MySQL的charset=utf8 没有-
	cursorl = conn.cursor()
	#添加
	sql = "insert into test(name) value('王中阳')"
	#修改
	# sql = "update test set name = '张云霞' where name = '王中阳'"
	#删除
	# sql = "delete from test where id = 1"
	#sql语句参数化
	iname = raw_input("请输入名字")
	params = [iname]
	# sql = "insert into test(name) value(%s)"
	sql = "update test set name = '小二1' where name = %s"
	res = cursorl.execute(sql,params)
	print(res)

	conn.commit()
	cursorl.close()
	conn.close()

except Exception,e:
	print(e.message)
